package org.hxzon.cyclone.plinks;

import java.util.List;

import org.hxzon.cyclone.Vector3;
import org.hxzon.cyclone.pcontacts.ParticleContact;

//绳索约束
public class ParticleCableConstraint extends ParticleConstraint {
    public double maxLength;

    public double restitution;

    public int addContact(List<ParticleContact> contacts) {
        double length = currentLength();

        if (length < maxLength) {
            return 0;
        }

        ParticleContact contact = new ParticleContact();
        contacts.add(contact);

        contact.particle[0] = particle;
        contact.particle[1] = null;

        Vector3 normal = anchor.minus(particle.getPosition());
        normal.normalise();
        contact.contactNormal = normal;

        contact.penetration = length - maxLength;
        contact.restitution = restitution;

        return 1;
    }

}
